package com.chance.cc.crawler.development.bootstrap.weibo.subscribe;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpConstant;
import com.chance.cc.crawler.core.downloader.HttpRequestBody;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import org.apache.commons.lang3.StringUtils;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2021/4/30 14:17
 * @Description
 **/
public class WeiboApiSubscribeUserIdInteraction {
    private static final String domain = "weibo";

    public static void main(String[] args) {


    }

    private static void sys(){
        String url = "https://c.api.weibo.com/2/statuses/count/biz.json";
        String site = "subscribeUserId";
        String siteBiz = "dingyue_userId-trace";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 + 1,null))
                .needParsed(false)
                .releaseTime(System.currentTimeMillis())
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .build();
        crawlerRequestRecord.setDownload(false);
        crawlerRequestRecord.setSkipPipeline(true);
        crawlerRequestRecord.tagsCreator().bizTags().addDomain(domain);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(site);
        crawlerRequestRecord.tagsCreator().bizTags().addSiteBiz(siteBiz);
//        crawlerRequestRecord.getHttpRequest().addExtra("source",source);

        //获取地址的时候需要添加site确定拿取到的地址为本次需要的
        String requestQueueName = StringUtils.joinWith("-","crawler",domain,site,siteBiz,"queue");
        CrawlerRequestRecord initCrawlerRecord = CrawlerRequestRecord.builder()
                .startPageRequest("weibo_post_request",turnPageItem)
//                .httpUrl("http://"+service_ip+":"+service_port+"/crawler/domain/common/api/v1/"+domain+"/results/queue/init?requestQueueName="+requestQueueName + "&site=dingyue_userId_post&hourFromNow=26")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();
        HttpRequestBody jsonBody = HttpRequestBody.json(JSON.toJSONString(crawlerRequestRecord), "utf-8");
        initCrawlerRecord.getHttpRequest().setMethod(HttpConstant.Method.POST);
        initCrawlerRecord.getHttpRequest().setRequestBody(jsonBody);
    }
}
